package com.link.base.core.basic.config.mvc;

import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import org.springframework.web.servlet.DispatcherServlet;

@Configuration
public class WebInitializer {

    /**
     * 配置springmvcservlet,保证前端请求的url可以放到到controller
     * @return
     */
    @Bean
    public ServletRegistrationBean springMvcServlet() {
        AnnotationConfigWebApplicationContext applicationContext = new AnnotationConfigWebApplicationContext();
        DispatcherServlet dispatcherServlet = new DispatcherServlet(applicationContext);
        ServletRegistrationBean registrationBean = new ServletRegistrationBean(dispatcherServlet, new String[0]);
        registrationBean.setLoadOnStartup(2);
        registrationBean.addUrlMappings(new String[]{"/action/*"});
        registrationBean.setName("springmvc");
        return registrationBean;
    }
}
